﻿#region Legal notice
/*
 * This file is part of EPPLib.
 * Copyright 2010, 2011 
 * Gianluca Esposito (info@gianlucaesposito.it)
 * ----------------------------------------------------------------------------
 * EPPLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * EPPLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Nome-Programma; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;

namespace EPPLib.Managers
{
    public class LogDataManager
    {
        #region Constants
        private const string COMMUNICATION_STRING_FORMAT = "Request:\r\n{0}\r\nResponse:\r\n{1}\r\n";
        #endregion

        #region Members
        private static readonly ILog _logger = LogManager.GetLogger(typeof(LogDataManager));
        private static object _syncRoot = new object();
        private static volatile LogDataManager _instance;
        #endregion

        #region Properties
        public static LogDataManager Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_syncRoot)
                    {
                        if (_instance == null)
                            _instance = new LogDataManager();
                    }
                }
                return _instance;
            }
        }
        #endregion

        #region Contructor(s)
        private LogDataManager()
        {
            // XmlConfigurator.Configure();
        }
        #endregion

        #region Public methods
        public void LogCommunication(string request, string response)
        {
            LogInfo(string.Format(COMMUNICATION_STRING_FORMAT, request, response));
        }
        public void LogInfo(string message)
        {
            if (_logger.IsInfoEnabled) _logger.Info(message);
        }
        public void LogInfo(string message, Exception ex)
        {
            if (_logger.IsInfoEnabled) _logger.Info(message, ex);
        }

        public void LogFatal(string message)
        {
            if (_logger.IsFatalEnabled) _logger.Fatal(message);
        }
        public void LogFatal(string message, Exception ex)
        {
            if (_logger.IsFatalEnabled) _logger.Fatal(message, ex);
        }

        public void LogDebug(string message)
        {
            if (_logger.IsDebugEnabled) _logger.Debug(message);
        }
        public void LogDebug(string message, Exception ex)
        {
            if (_logger.IsDebugEnabled) _logger.Debug(message, ex);
        }

        public void LogError(string message)
        {
            if (_logger.IsErrorEnabled) _logger.Error(message);
        }
        public void LogError(string message, Exception ex)
        {
            if (_logger.IsErrorEnabled) _logger.Error(message, ex);
        }

        public void LogWarn(string message)
        {
            if (_logger.IsWarnEnabled) _logger.Warn(message);
        }
        public void LogWarn(string message, Exception ex)
        {
            if (_logger.IsWarnEnabled) _logger.Warn(message, ex);
        }
        #endregion
    }
}
